package cn.semcorp.zhuhaizj.services.impl;

import cn.semcorp.zhuhaizj.common.Common;
import cn.semcorp.zhuhaizj.exception.ServiceException;
import cn.semcorp.zhuhaizj.listener.ReadClassDateListener;
import cn.semcorp.zhuhaizj.listener.ReadCoatingDateListener;
import cn.semcorp.zhuhaizj.listener.ReadPulpingDateListener;
import cn.semcorp.zhuhaizj.mapper.UtilizationMapper;
import cn.semcorp.zhuhaizj.pojo.dto.*;
import cn.semcorp.zhuhaizj.pojo.entity.SlurrySolidEntity;
import cn.semcorp.zhuhaizj.pojo.entity.UtilizationEntityDay;
import cn.semcorp.zhuhaizj.pojo.entity.UtilizationEntityShift;
import cn.semcorp.zhuhaizj.pojo.entity.WorkshopEntity;
import cn.semcorp.zhuhaizj.pojo.vo.*;
import cn.semcorp.zhuhaizj.repo.IRedisRepository;
import cn.semcorp.zhuhaizj.restful.ResponseCode;
import com.alibaba.excel.EasyExcel;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.IsoFields;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static cn.semcorp.zhuhaizj.common.Common.*;

/**
 * 利用率实现类
 */
@Slf4j
@Service
public class UtilizationServiceImpl {
    /**
     * dao层装配
     * @param utilizationFile
     */
    @Autowired
    private UtilizationMapper readUtilizationMapper;
    @Autowired
    private IRedisRepository redisRepository;

    /**
     * 数据核对 - 查询
     * @param
     * @param <T>
     * @return
     */
    public <T> List<T> clickQuery(ClickQueryDTO dto) {
//        String start = String.valueOf(LocalDate.parse(dateStart.split("T")[0]).plusDays(1));
//        String end = String.valueOf(LocalDate.parse(dateEnd.split("T")[0]).plusDays(1));
        if (dto.getModel().equals(common95)){
            return (List<T>) readUtilizationMapper.selectUtilizationShiftByDateRang(dto);
        }
        if (dto.getModel().equals(common94)){
            return (List<T>) readUtilizationMapper.selectUtilizationDayByDateRang(dto);
        }
        return null;
    }

    /**
     * 趋势图 - 损耗查询 近一个月
     * @param machine
     * @Return
     */
    public List<SelectMachineLossVO> selectLossByMachine(String machine){
        String start = String.valueOf(Common.getBeforeNowDate());
        String end = String.valueOf(Common.getBefore3TenNowDate());
        List<String> dates = getAllDatesBetweenTwoDates(Common.getBefore3TenNowDate(), Common.getBeforeNowDate());
        List<SelectMachineLossVO> list = new ArrayList<>();
        List<SelectMachineLossVO> utilizationDayVOS = readUtilizationMapper.selectLossByMachine(start,end,machine);


        for (String date : dates) {
            int state = 0 ;
            SelectMachineLossVO s = new SelectMachineLossVO();
            s.setDate(date);
            for (SelectMachineLossVO utilizationDayVO : utilizationDayVOS) {
                if (utilizationDayVO.getDate().equals(date)){
                    state = 1;
                    s.setMl(utilizationDayVO.getMl().replace("%", ""));
                    s.setSl(utilizationDayVO.getSl().replace("%", ""));
                    s.setTl(utilizationDayVO.getTl().replace("%", ""));
                }
            }
            if (state == 0){
                s.setMl("-");
                s.setSl("-");
                s.setTl("-");
            }
            list.add(s);
        }
        return list;
    }

    /**
     * 数据核对 - 初始化 - 查询今日班次利用率
     * @return
     */
    public List<UtilizationShiftVO> selectUtilizationShift() {
        String date = String.valueOf(Common.getBeforeNowDate());
        return readUtilizationMapper.selectUtilizationShift(date);
    }

    /**
     * 单系列查询 - 根据车间查询机台列表
     * @param workshop
     * @return
     */
    public List<MachineSortVO> selectMachineByWorkshop(String workshop){
        return readUtilizationMapper.selectMachineNameByWorkshop(workshop);
    }

    /** 0 辅助
     * 单系列查询 - 初始化 - 查询机台名称列表
     * @return
     */
    public List<MachineSortVO> selectMachine(){
        return readUtilizationMapper.selectMachineName();
    }

    /** 0 辅助
     * 单系列查询 - 初始化 - 查询涂布车间列表  固定表
     * @return
     */
    public List<WorkshopVO> selectWorkshopList(){
        log.info("从Redis查询涂布车间缓存数据执行中...");
        List<WorkshopVO> list = redisRepository.getCoatingWorkshop();
        if (list.size() != 0){
            log.info("Redis涂布车间缓存数据命中成功!");
            return list;
        }
        log.info("Redis涂布车间缓存数据命中失败,开始执行查询Mysql业务逻辑...");
        List<WorkshopVO> workshopVOS = readUtilizationMapper.selectWorkshopList();
        log.info("Mysql查询涂布车间执行业务逻辑成功!");
        log.info("向Redis缓存涂布车间数据执行中...");
        redisRepository.saveCoatingWorkshop(workshopVOS);
        log.info("向Redis缓存涂布车间数据执行成功!");
        return workshopVOS;
    }

    /**
     * 每日改善 - 修改原因、措施
     * @param utilizationDTO
     */
    public void updateLowUtilizationDayResultMeasure(UpdateLowUtilizationDTO utilizationDTO) {
        int id = Integer.parseInt(utilizationDTO.getId());
        String result = utilizationDTO.getResult();
        String measureResult = utilizationDTO.getMeasureResult();
        readUtilizationMapper.updateLowUtilizationDayResultMeasure(id,result,measureResult);
    }

    /**
     * 每日改善 - 查询修改信息
     * @param id
     * @return
     */
    public SelectLowUtilizationVO selectLowUtilizationById(String id){
        return readUtilizationMapper.selectLowUtilizationById(id);
    }

    /**
     * 手动上传制浆
     */
    public void updatePulping(List<PulpingDTO> list) {
        String date = String.valueOf(Common.getBeforeNowDate());
        for (PulpingDTO pulpingDTO : list) {
            pulpingDTO.setDate(date);
        }
        readUtilizationMapper.updatePulping(list);
    }

    /**
     * 手动上传涂布
     */
    public void updateCoating(List<CoatingDTO> list) {
        String date = String.valueOf(Common.getBeforeNowDate());
        for (CoatingDTO coatingDTO : list) {
            coatingDTO.setDate(date);
        }
        readUtilizationMapper.updateCoating(list);
    }

    /**
     * 基础 - 导入今日日次低利用率、异常(生成咋日)
     */
    public int quartzInsertLowUtilizationDay(String beforeNowDate){
        List<SelectLowUtilizationVO> selectLowUtilizationVOS = readUtilizationMapper.selectLowUtilizationDay(beforeNowDate,Common.commonEligibleYES);
        if (selectLowUtilizationVOS == null || selectLowUtilizationVOS.size() == 0){
            return 0;
        }
        for (SelectLowUtilizationVO selectLowUtilizationVO : selectLowUtilizationVOS) {
            String workshop = selectLowUtilizationVO.getWorkshop();
            if (workshop.equals("涂布A1车间") || workshop.equals("涂布A2车间")){
                selectLowUtilizationVO.setDuty("陈功元");
            }else if (workshop.equals("涂布B小车间") || workshop.equals("涂布B大车间")){
                selectLowUtilizationVO.setDuty("郭鱼鹏");
            }else if (workshop.equals("涂布C车间") || workshop.equals("涂布D车间") || workshop.equals("涂布在线车间")){
                selectLowUtilizationVO.setDuty("雷越");
            }
        }
        readUtilizationMapper.insertLowUtilizationDay(selectLowUtilizationVOS);
        return 1;
    }

    /**
     * 基础 - 导入班次利用率(生成咋日)
     */
    public int quartzInsertShiftUtilization(String date){
        List<SlurrySolidEntity> voList = readUtilizationMapper.selectAllSolid();
        // 转为Map
        // 固含量
        Map<String, String> solidMap = voList.stream()
                .collect(Collectors.toMap(SlurrySolidEntity::getSlurryName, SlurrySolidEntity::getSlurrySolidContent));
        // 浆料类型
        Map<String, String> modelMap = voList.stream()
                .collect(Collectors.toMap(SlurrySolidEntity::getSlurryName, SlurrySolidEntity::getSlurryModel));

        // 车间
        List<WorkshopEntity> workshopEntities = readUtilizationMapper.selectAllWorkshop();
        Map<String, String> workshopMap = workshopEntities.stream()
                .collect(Collectors.toMap(WorkshopEntity::getMachineName, WorkshopEntity::getCoatingWorkshop));

        // 建立机台集合
        List<UtilizationEntityShift> entities = new ArrayList<>();
        List<String> machineA1List = Common.getCommonMachineList();

        /**
         * 数据导入测试
         */
//        LocalDate startDate = LocalDate.of(2023, 1, 1);
//        LocalDate endDate = LocalDate.of(2024, 1, 17);
//
//        List<String> dateList = new ArrayList<>();
//
//        while (!startDate.isAfter(endDate)) {
//            dateList.add(String.valueOf(startDate));
//            startDate = startDate.plusDays(1);
//        }
        for (String machineName1 : machineA1List) {
            String workshop = workshopMap.get(machineName1);
            // 涂布产出数据
            List<SelectCoatingDataVO> selectCoatingAreaVOS =
                    readUtilizationMapper.selectShiftOfCoating(date, machineName1);
            // 没有当前机台涂布产出,跳过
            if (selectCoatingAreaVOS == null || selectCoatingAreaVOS.size() == 0) {
                continue;
            }
            for (SelectCoatingDataVO selectCoatingAreaVO : selectCoatingAreaVOS) {
                // 每条记录属性全归零
                String classType = selectCoatingAreaVO.getClassType();
                String machineName = selectCoatingAreaVO.getMachineName();
                String slurryName = selectCoatingAreaVO.getSlurryName();
                String ticketNumber = selectCoatingAreaVO.getTicketNumber();
                String productModel = selectCoatingAreaVO.getProductModel();
                double theoreticalOutputArea1 = 0; // 理论产出面积(标准)
                double theoreticalOutputArea2 = 0; // 理论产出面积(实际)
                double theoreticalSlurryUtilization = 0; // 浆料利用率(标准)
                double actualSlurryUtilization = 0; // 浆料利用率(实际)
                double actualInvestmentArea = 0; // 实际投入面积
                double actualOutputArea = 0; // 实际产出面积
                double adjustmentLoss = 0; // 调机损率
                double yieldLoss = 0; // 收率损率
                double scrapLoss = 0; // 报废损率
                double arealLoss = 0; // 面密度损率
                double adjustmentLossArea = 0; // 调机损耗面积
                double coatingFilmScrapped = 0; // 涂布膜报废面积
                double slurryFilmQuantity = 0; // 浆料报废重量
                double slurryWeightShift = 0; // 浆料报废重量
                double yieldLossArea = 0; // 收率损耗面积
                double arealLossArea = 0; // 面密度损耗面积
                // 每条涂布产出记录
                UtilizationEntityShift utilizationEntityShift = new UtilizationEntityShift();
                String model = modelMap.get(slurryName);
                if (model == null || model.equals("")) {
                    model = "";
                }
                String standardArealDensity = selectCoatingAreaVO.getStandardArealDensity();
                String actualArealDensity = selectCoatingAreaVO.getActualArealDensity();
                // 获取周次/月年
                LocalDate inputDate = LocalDate.parse(date);
                String year = String.valueOf(inputDate.getYear());
                // 周次 202352
                String weekNumber = year+inputDate.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
                String yearMonth = date.substring(0,7);
                // 是否停机
                // 实际投入面积 实际产出面积 收率损耗面积
                String input = selectCoatingAreaVO.getActualInvestmentArea();
                String output = selectCoatingAreaVO.getActualOutputArea();
                if (Common.isNumber(input) && Common.isNumber(output)){
                    actualInvestmentArea = Double.parseDouble(selectCoatingAreaVO.getActualInvestmentArea());
                    if (Common.isNumber(selectCoatingAreaVO.getActualOutputArea())){
                        actualOutputArea = Double.parseDouble(selectCoatingAreaVO.getActualOutputArea());
                        yieldLossArea = Double.parseDouble(selectCoatingAreaVO.getActualInvestmentArea())
                                - Double.parseDouble(selectCoatingAreaVO.getActualOutputArea());
                    }

                }
                if (!Common.isNumber(input) || input.equals("0")){
                    utilizationEntityShift.setDate(date);
                    utilizationEntityShift.setWeek(weekNumber);
                    utilizationEntityShift.setActualArealDensity("");
                    utilizationEntityShift.setStandardArealDensity("");
                    utilizationEntityShift.setYearMonth(yearMonth);
                    utilizationEntityShift.setMachineName(machineName);
                    utilizationEntityShift.setScrapWeight("0");
                    utilizationEntityShift.setClassType(classType);
                    utilizationEntityShift.setSlurryName(slurryName);
                    utilizationEntityShift.setSlurryModel(model);
                    utilizationEntityShift.setTicketNumber("");
                    utilizationEntityShift.setProductModel("");
                    utilizationEntityShift.setWorkshop(workshop);
                    utilizationEntityShift.setSlurryWeightAll("0");
                    utilizationEntityShift.setActualInputArea("0");
                    utilizationEntityShift.setActualOutputArea("0");
                    utilizationEntityShift.setTheoreticalOutputArea1("0");
                    utilizationEntityShift.setTheoreticalOutputArea2("0");
                    utilizationEntityShift.setTheoreticalSlurryUtilization("");
                    utilizationEntityShift.setActualSlurryUtilization("");
                    utilizationEntityShift.setAdjustmentLoss("");
                    utilizationEntityShift.setAdjustmentLossArea("0");
                    utilizationEntityShift.setYieldLoss("");
                    utilizationEntityShift.setYieldLossArea("0");
                    utilizationEntityShift.setScrapLoss(""); // 报废损率
                    utilizationEntityShift.setScrapLossArea("0");
                    utilizationEntityShift.setArealLoss("");
                    utilizationEntityShift.setArealLossArea("0");
                    utilizationEntityShift.setLossAll("");
                    utilizationEntityShift.setOtherLoss("");
                    utilizationEntityShift.setEligibility("停机");
                    entities.add(utilizationEntityShift);
                    continue;
                }


                // 计算机台总调机损耗面积综合
                if (Common.isNumber(selectCoatingAreaVO.getAdjustmentLossArea())) {
                    adjustmentLossArea = Double.parseDouble(selectCoatingAreaVO.getAdjustmentLossArea());
                }

                // 计算机台总涂布膜报废面积
                if (Common.isNumber(selectCoatingAreaVO.getCoatingFilmScrapped())) {
                    coatingFilmScrapped = Double.parseDouble(selectCoatingAreaVO.getCoatingFilmScrapped());
                }

                // 计算机台总浆料报废重量
                if (Common.isNumber(selectCoatingAreaVO.getSlurryFilmWeight())) {
                    slurryFilmQuantity += Double.parseDouble(selectCoatingAreaVO.getSlurryFilmWeight());
                }

                /**
                 * 浆料使用量计算
                 */
                // 循环系统
                if (Common.isNumber(selectCoatingAreaVO.getSuccessionTraffic()) || Common.isNumber(selectCoatingAreaVO.getShiftFlow())) {
                    double begin = Double.parseDouble(selectCoatingAreaVO.getSuccessionTraffic());
                    double end = Double.parseDouble(selectCoatingAreaVO.getShiftFlow());
                    double diffSystem = end - begin; // 可以为0
                    // 满足是循环系统供料
                    if (selectCoatingAreaVO.getSlurryName().equals(Common.commonSlurryName)) {
                        slurryWeightShift += diffSystem * Common.value1;
                    }else{
                        slurryWeightShift += diffSystem * Common.value2;
                    }
                }else{
                    // 制浆领用数据
                    String classType1 = selectCoatingAreaVO.getClassType();
                    List<SelectPulpingDataVO> selectPulpingDataVOS
                            = readUtilizationMapper.selectPulpingForPacking(date, machineName, classType1);
                    if (selectPulpingDataVOS.size() != 0) {
                        for (SelectPulpingDataVO selectPulpingDataVO : selectPulpingDataVOS) {
                            // 当前记录制浆领用的工单号
                            String ticketNumberPulping = selectPulpingDataVO.getTicketNumber();
                            String productModelPulping = selectPulpingDataVO.getProductModel();
                            // 当前记录涂布产出的工单号
                            int length = selectCoatingAreaVO.getTicketNumber().length();
                            String ticketNumberCoating = selectCoatingAreaVO.getTicketNumber().substring(3,length);
                            String productModelCoating = selectCoatingAreaVO.getProductModel();
                            if (ticketNumberCoating.equals(ticketNumberPulping)) {
                                if (Common.isNumber(selectPulpingDataVO.getPickingQuantity())){
                                    slurryWeightShift += Double.parseDouble(selectPulpingDataVO.getPickingQuantity());
                                }
                            }
                        }
                    }
                }

                // 桶装领料
                if (Common.isNumber(selectCoatingAreaVO.getSuccessorSlurryWeight())  &&   Common.isNumber(selectCoatingAreaVO.getShiftSlurryWeight())) {
                    double handWeight = Double.parseDouble(selectCoatingAreaVO.getSuccessorSlurryWeight());
                    double endWeight = Double.parseDouble(selectCoatingAreaVO.getShiftSlurryWeight());
                    double diffBucket = handWeight - endWeight;
                    slurryWeightShift += diffBucket;
                }


                /**
                 * 利用率计算
                 */
                // 理论产出 = 浆料使用量 * 固含量 / 标准面密度
                String solids = solidMap.get(selectCoatingAreaVO.getSlurryName());

                if (!Common.isNumber(solids)) {
                    // 试验料
                    utilizationEntityShift.setDate(date);
                    utilizationEntityShift.setWeek(weekNumber);
                    utilizationEntityShift.setActualArealDensity(actualArealDensity);
                    utilizationEntityShift.setSlurryModel(model);
                    utilizationEntityShift.setStandardArealDensity(standardArealDensity);
                    utilizationEntityShift.setYearMonth(yearMonth);
                    utilizationEntityShift.setMachineName(machineName);
                    utilizationEntityShift.setClassType(classType);
                    utilizationEntityShift.setSlurryName(slurryName);
                    utilizationEntityShift.setTicketNumber(ticketNumber);
                    utilizationEntityShift.setProductModel(model);
                    utilizationEntityShift.setScrapWeight(Common.transformTwoNumber(slurryFilmQuantity));
                    utilizationEntityShift.setWorkshop(workshop);
                    utilizationEntityShift.setSlurryWeightAll(Common.transformTwoNumber(slurryWeightShift));
                    utilizationEntityShift.setActualInputArea(Common.transformTwoNumber(actualInvestmentArea));
                    utilizationEntityShift.setActualOutputArea(Common.transformTwoNumber(actualOutputArea));
                    utilizationEntityShift.setTheoreticalOutputArea1(Common.transformTwoNumber(theoreticalOutputArea1));
                    utilizationEntityShift.setTheoreticalOutputArea2("0");
                    utilizationEntityShift.setTheoreticalSlurryUtilization("");
                    utilizationEntityShift.setActualSlurryUtilization("");
                    utilizationEntityShift.setAdjustmentLoss("");
                    utilizationEntityShift.setAdjustmentLossArea("0");
                    utilizationEntityShift.setYieldLoss("");
                    utilizationEntityShift.setYieldLossArea("0");
                    utilizationEntityShift.setScrapLoss(""); // 报废损率
                    utilizationEntityShift.setScrapLossArea("0");
                    utilizationEntityShift.setArealLoss("");
                    utilizationEntityShift.setArealLossArea("0");
                    utilizationEntityShift.setLossAll("");
                    utilizationEntityShift.setOtherLoss("");
                    utilizationEntityShift.setEligibility("实验/样品");
                    entities.add(utilizationEntityShift);
                    continue;
                }

                double standard = 0;
                double actual = 0;
                double solid = Double.parseDouble(solids);
                if (Common.isNumber(selectCoatingAreaVO.getStandardArealDensity())){
                    standard = Double.parseDouble(selectCoatingAreaVO.getStandardArealDensity());
                    theoreticalOutputArea1 = (slurryWeightShift * solid / standard) * 1000;  // 单条记录的理论产出
                }else{
                    theoreticalOutputArea1 = 0 ;
                }

                if (Common.isNumber(selectCoatingAreaVO.getActualArealDensity())){
                    actual = Double.parseDouble(selectCoatingAreaVO.getActualArealDensity());
                    theoreticalOutputArea2 = (slurryWeightShift * solid / actual) * 1000;
                }else{
                    theoreticalOutputArea2 = 0 ;
                }

                // 单条记录面密度差异 含正负值
                if (standard != 0){
                    double arealDiff = (actual - standard) / standard;
                    arealLossArea = ((slurryWeightShift * solid / standard) * 1000) * arealDiff;
                }else{
                    arealLossArea = 0 ;
                }


                /**
                 * 损率/利用率计算
                 */
                double all = (slurryFilmQuantity * Double.parseDouble(solids)) / Double.parseDouble(standardArealDensity);
                if (theoreticalOutputArea1 == 0 && theoreticalOutputArea2 == 0){
                    theoreticalSlurryUtilization = 0;
                    actualSlurryUtilization = 0 ;
                    adjustmentLoss = 0 ;
                    yieldLoss = 0;
                    scrapLoss = 0 ;
                    arealLoss = 0 ;
                }else{
                    theoreticalSlurryUtilization = actualOutputArea / theoreticalOutputArea1;
                    actualSlurryUtilization = actualOutputArea / theoreticalOutputArea2;
                    // 损率
                    adjustmentLoss = adjustmentLossArea / theoreticalOutputArea1;
                    yieldLoss = yieldLossArea / theoreticalOutputArea1;
                    scrapLoss = (coatingFilmScrapped + all) / theoreticalOutputArea1;
                    arealLoss = arealLossArea / theoreticalOutputArea1;
                }

                // 对象属性
                utilizationEntityShift.setDate(date);
                utilizationEntityShift.setStandardArealDensity(standardArealDensity);
                utilizationEntityShift.setActualArealDensity(actualArealDensity);
                utilizationEntityShift.setSlurryModel(model);
                utilizationEntityShift.setWeek(weekNumber);
                utilizationEntityShift.setYearMonth(yearMonth);
                utilizationEntityShift.setMachineName(machineName);
                utilizationEntityShift.setScrapWeight(Common.transformTwoNumber(slurryFilmQuantity));
                utilizationEntityShift.setClassType(classType);
                utilizationEntityShift.setSlurryName(slurryName);
                utilizationEntityShift.setTicketNumber(ticketNumber);
                utilizationEntityShift.setProductModel(productModel);
                utilizationEntityShift.setWorkshop(workshop);
                utilizationEntityShift.setSlurryWeightAll(Common.transformTwoNumber(slurryWeightShift));
                utilizationEntityShift.setActualInputArea(Common.transformTwoNumber(actualInvestmentArea));
                utilizationEntityShift.setActualOutputArea(Common.transformTwoNumber(actualOutputArea));
                utilizationEntityShift.setTheoreticalOutputArea1(Common.transformTwoNumber(theoreticalOutputArea1));
                utilizationEntityShift.setTheoreticalOutputArea2(Common.transformTwoNumber(theoreticalOutputArea2));
                utilizationEntityShift.setTheoreticalSlurryUtilization(Common.transformPercent(theoreticalSlurryUtilization));
                utilizationEntityShift.setActualSlurryUtilization(Common.transformPercent(actualSlurryUtilization));
                utilizationEntityShift.setAdjustmentLoss(Common.transformPercent(adjustmentLoss));
                utilizationEntityShift.setAdjustmentLossArea(Common.transformTwoNumber(adjustmentLossArea));
                utilizationEntityShift.setYieldLoss(Common.transformPercent(yieldLoss));
                utilizationEntityShift.setYieldLossArea(Common.transformTwoNumber(yieldLossArea));
                utilizationEntityShift.setScrapLoss(Common.transformPercent(scrapLoss)); // 报废损率
                utilizationEntityShift.setScrapLossArea(Common.transformTwoNumber(coatingFilmScrapped + all));
                utilizationEntityShift.setArealLoss(Common.transformPercent(arealLoss));
                utilizationEntityShift.setArealLossArea(Common.transformTwoNumber(arealLossArea));
                utilizationEntityShift.setLossAll(Common.transformPercent(1 - theoreticalSlurryUtilization));
                utilizationEntityShift.setOtherLoss(Common.transformPercent(1 - theoreticalSlurryUtilization - adjustmentLoss - yieldLoss - arealLoss));
                if ((theoreticalSlurryUtilization  >= Common.value3 && theoreticalSlurryUtilization <= Common.value4)) {
                    // 在0.98 - 1.00 区间为合格
                    utilizationEntityShift.setEligibility("是");
                }else if (theoreticalSlurryUtilization  < Common.value3 && theoreticalSlurryUtilization > 0){
                    // 在0 - 0.98 区间为不合格
                    utilizationEntityShift.setEligibility("否");
                }else {
                    utilizationEntityShift.setEligibility("异常");
                }
//                if (theoreticalSlurryUtilization > 0 && actualSlurryUtilization > 0){
//                    utilizationEntityShift.setEligibility("正常");
//                }else{
//                    utilizationEntityShift.setEligibility("异常");
//                }
                // 添加到集合
                entities.add(utilizationEntityShift);
            }
        }

        List<UtilizationShiftVO> utilizationShiftVOS = readUtilizationMapper.selectUtilizationShift(date);
        if (utilizationShiftVOS.size() != 0){
            return 0;
        }

        if (entities.size() == 0){
            return 0;
        }
        readUtilizationMapper.insertUtilizationShift(entities);
        return 1;
    }

    /**
     * 基础 - 导入日次利用率(生成咋日)
     */
    public int quartzInsertDayUtilization(String date) {
        // 建立机台集合
        List<UtilizationEntityDay> entities = new ArrayList<>();
        List<String> machineList = Common.getCommonMachineList();

        for (String machineName : machineList) {
            // 定义属性
            double theoreticalOutputArea1 = 0; // 理论产出面积(标准)
            double theoreticalOutputArea2 = 0; // 理论产出面积(实际)
            double theoreticalSlurryUtilization = 0; // 浆料利用率(标准)
            double actualSlurryUtilization = 0; // 浆料利用率(实际)
            double actualInvestmentArea = 0; // 实际投入面积
            double actualOutputArea = 0; // 实际产出面积
            double adjustmentLoss = 0; // 调机损率
            double yieldLoss = 0; // 收率损率
            double scrapLoss = 0; // 报废损率
            double arealLoss = 0; // 面密度损率
            double adjustmentLossArea = 0; // 调机损耗面积
            double coatingFilmScrapped = 0; // 涂布膜报废面积
            double slurryFilmQuantity = 0; // 浆料报废重量
            double yieldLossArea = 0; // 收率损耗面积
            double slurryWeightAll = 0; // 使用浆料总和
            double arealLossArea = 0; // 面密度损耗面积
            UtilizationEntityDay utilizationEntity = new UtilizationEntityDay();

            // 查询机台的涂布车间
            String workshop = readUtilizationMapper.selectWorkshopByMachine(machineName);
            String yearMonth = date.substring(0,7);
            // 涂布产出数据
            List<UtilizationShiftVO> selectCoatingAreaVOS =
                    readUtilizationMapper.selectShift(date, machineName);
            // 没有当前机台涂布产出,跳过
            if (selectCoatingAreaVOS == null || selectCoatingAreaVOS.size() == 0) {
                continue;
            }
            for (UtilizationShiftVO selectCoatingAreaVO : selectCoatingAreaVOS) {
                // 计算机台总实际投入面积和
                if (Common.isNumber(selectCoatingAreaVO.getActualInputArea()) && Common.isNumber(selectCoatingAreaVO.getActualOutputArea())){
                    actualInvestmentArea += Double.parseDouble(selectCoatingAreaVO.getActualInputArea());
                    actualOutputArea += Double.parseDouble(selectCoatingAreaVO.getActualOutputArea());
                    yieldLossArea = Double.parseDouble(selectCoatingAreaVO.getActualInputArea())
                            - Double.parseDouble(selectCoatingAreaVO.getActualOutputArea());
                }
                // 计算机台总调机损耗面积综合
                if (Common.isNumber(selectCoatingAreaVO.getAdjustmentLossArea())) {
                    adjustmentLossArea += Double.parseDouble(selectCoatingAreaVO.getAdjustmentLossArea());
                }
                // 计算机台总涂布膜报废面积
                if (Common.isNumber(selectCoatingAreaVO.getScrapLossArea() )) {
                    coatingFilmScrapped += Double.parseDouble(selectCoatingAreaVO.getScrapLossArea());
                }

                // 计算机台总浆料报废重量
                if (Common.isNumber(selectCoatingAreaVO.getScrapWeight())) {
                    slurryFilmQuantity += Double.parseDouble(selectCoatingAreaVO.getScrapWeight());
                }

                if (Common.isNumber(selectCoatingAreaVO.getArealLossArea())){
                    arealLossArea += Double.parseDouble(selectCoatingAreaVO.getArealLossArea());
                }
                // 浆料使用量
                if (Common.isNumber(selectCoatingAreaVO.getSlurryWeightAll())) {
                    slurryWeightAll += Double.parseDouble(selectCoatingAreaVO.getSlurryWeightAll());
                }
                if (Common.isNumber(selectCoatingAreaVO.getTheoreticalOutputArea1())){
                    theoreticalOutputArea1 += Double.parseDouble(selectCoatingAreaVO.getTheoreticalOutputArea1());
                }
                if (Common.isNumber(selectCoatingAreaVO.getTheoreticalOutputArea2())){
                    theoreticalOutputArea2 += Double.parseDouble(selectCoatingAreaVO.getTheoreticalOutputArea2());
                }
            }

            // 利用率
            theoreticalSlurryUtilization = 0 ;
            actualSlurryUtilization = 0 ;
            adjustmentLoss = 0 ;
            yieldLoss = 0 ;
            scrapLoss = 0 ;
            arealLoss = 0 ;
            if (theoreticalOutputArea1 != 0 && theoreticalOutputArea2 != 0){
                theoreticalSlurryUtilization = actualOutputArea / theoreticalOutputArea1;
                actualSlurryUtilization = actualOutputArea / theoreticalOutputArea2;
                // 损率
                adjustmentLoss = adjustmentLossArea / theoreticalOutputArea1;
                yieldLoss = yieldLossArea / theoreticalOutputArea1;
                scrapLoss = coatingFilmScrapped / theoreticalOutputArea1;
                arealLoss = arealLossArea / theoreticalOutputArea1;
            }

            LocalDate inputDate = LocalDate.parse(date);
            String year = String.valueOf(inputDate.getYear());
            // 获取日期对应的周次
            String weekNumber = year+inputDate.get(IsoFields.WEEK_OF_WEEK_BASED_YEAR);
            // 对象属性
            utilizationEntity.setDate(date);
            utilizationEntity.setWorkshop(workshop);
            utilizationEntity.setWeek(weekNumber);
            utilizationEntity.setYearMonth(yearMonth);
            utilizationEntity.setMachineName(machineName);
            utilizationEntity.setScrapWeight(Common.transformTwoNumber(slurryFilmQuantity));
            utilizationEntity.setSlurryWeightAll(Common.transformTwoNumber(slurryWeightAll));
            utilizationEntity.setActualInputArea(Common.transformTwoNumber(actualInvestmentArea));
            utilizationEntity.setActualOutputArea(Common.transformTwoNumber(actualOutputArea));
            utilizationEntity.setTheoreticalOutputArea1(Common.transformTwoNumber(theoreticalOutputArea1));
            utilizationEntity.setTheoreticalOutputArea2(Common.transformTwoNumber(theoreticalOutputArea2));
            utilizationEntity.setTheoreticalSlurryUtilization(Common.transformPercent(theoreticalSlurryUtilization));
            utilizationEntity.setActualSlurryUtilization(Common.transformPercent(actualSlurryUtilization));
            utilizationEntity.setAdjustmentLoss(Common.transformPercent(adjustmentLoss));
            utilizationEntity.setAdjustmentLossArea(Common.transformTwoNumber(adjustmentLossArea));
            utilizationEntity.setYieldLoss(Common.transformPercent(yieldLoss));
            utilizationEntity.setYieldLossArea(Common.transformTwoNumber(yieldLossArea));
            utilizationEntity.setScrapLoss(Common.transformPercent(scrapLoss)); // 报废损率
            utilizationEntity.setScrapLossArea(Common.transformTwoNumber(coatingFilmScrapped));
            utilizationEntity.setArealLoss(Common.transformPercent(arealLoss));
            utilizationEntity.setArealLossArea(Common.transformTwoNumber(arealLossArea));
            utilizationEntity.setLossAll(Common.transformPercent(1 - theoreticalSlurryUtilization));
            utilizationEntity.setOtherLoss(Common.transformPercent(1 - theoreticalSlurryUtilization - adjustmentLoss - yieldLoss - arealLoss));
            if (theoreticalSlurryUtilization  >= Common.value3 && theoreticalSlurryUtilization <= Common.value4) {
                // 在0.98 - 1.00 区间为合格
                utilizationEntity.setEligibility("是");
            }else if (theoreticalSlurryUtilization < Common.value3 && theoreticalSlurryUtilization > 0){
                // 在0 - 0.98 区间为不合格
                utilizationEntity.setEligibility("否");
            }else {
                // 其他情况为 异常
                utilizationEntity.setEligibility("异常/停机/实验");
            }
            entities.add(utilizationEntity);
        }

        List<UtilizationDayVO> utilizationDayVOS = readUtilizationMapper.selectUtilizationDay(date);
        if (utilizationDayVOS.size() != 0){
            return 0;
        }
        // 添加当天日利用率到数据库
        if (entities.size() == 0){
            return 0;
        }
        readUtilizationMapper.insertUtilizationDay(entities);
        return 1;
    }

    /**
     * 机台改善 - 初始化 - 查询低利用率
     * @return
     */
    public List<SelectLowUtilizationVO> loadSelectMeasureDay() {
        return readUtilizationMapper.loadSelectMeasureDay(String.valueOf(Common.getBeforeNowDate()));
    }

    /**
     * 机台改善 - 查询低利用率
     * @return
     */
    public List<SelectLowUtilizationVO> queryMeasureByRangTime(QueryMeasureDTO dto) {
//        String start = String.valueOf(LocalDate.parse(dateStart.split("T")[0]).plusDays(1));
//        String end = String.valueOf(LocalDate.parse(dateEnd.split("T")[0]).plusDays(1));
        return readUtilizationMapper.queryMeasureByRangTime(dto);
    }

    /**
     * 以下方法为趋势图
     */

    /** 趋势图 1 - 1
     * 图表 - 查询涂布综合日利用率
     * @return
     */
    public List<SelectAllUtilizationDayFigVO> queryAllDayUtilization(){
        log.debug("开始执行<查询综合日利用率>方法...");
        List<SelectAllUtilizationDayFigVO> sauList = new ArrayList<>();
        // 时间点
        String start = String.valueOf(Common.getBeforeNowDate());
        String end = String.valueOf(Common.getBefore3TenNowDate());
        // 时间集合 30
        List<String> ten = Common.getDateOneBetween3Ten();
        Collections.reverse(ten);
        // 查询
        List<SelectAllUtilizationVO> list = readUtilizationMapper.queryAllUtilizationDay(start, end);
        if (list == null || list.size() == 0){
            for (String date : ten) {
                SelectAllUtilizationDayFigVO sau = new SelectAllUtilizationDayFigVO();
                sau.setDate(date);
                sau.setL1("-");
                sau.setL2("-");
                sauList.add(sau);
            }
            return sauList;
        }
        for (String date : ten) {
            SelectAllUtilizationDayFigVO sau = new SelectAllUtilizationDayFigVO();
            double o1 = 0 ;
            double l1 = 0 ;
            double l2 = 0 ;

            for (SelectAllUtilizationVO vo : list) {
                String voDate = vo.getDate();
                if (date.equals(voDate)){
                    o1 += Double.parseDouble(vo.getActualOutputArea());
                    l1 += Double.parseDouble(vo.getTheoreticalOutputArea1());
                    l2 += Double.parseDouble(vo.getTheoreticalOutputArea2());
                }
            }
            sau.setDate(date);
            if (o1 == 0 || l1 == 0 || l2 == 0){
                sau.setL1("-");
                sau.setL2("-");
            }else{
                sau.setL1(Common.transformTwoNumber(o1/l1*100));
                sau.setL2(Common.transformTwoNumber(o1/l2*100));
            }
            sauList.add(sau);
        }
        log.debug("执行<查询综合日利用率>方法完毕!");
        return sauList;
    }

    /** 趋势图 1 - 2
     * 图表 - 查询涂布车间综合日利用率
     */
    public List<SelectAllWorkshopUtilizationVO> queryAllWorkshopUtilization(String date){
        log.debug("开始执行<查询涂布车间综合日利用率>方法...");
        List<SelectAllWorkshopUtilizationVO> sauList = new ArrayList<>();
        // 时间集合
        List<String> ten = Common.getDateOneBetweenTen();
        Collections.reverse(ten);
        // 查询
        List<SelectAllUtilizationVO> list = readUtilizationMapper.queryAllUtilizationDayOrderByWorkshopByDate(date);
        List<String> workshopList = Common.getAllWorkshop();
        if (list.size() == 0){
            for (String workshop : workshopList) {
                SelectAllWorkshopUtilizationVO weekVO = new SelectAllWorkshopUtilizationVO();
                weekVO.setWorkshop(workshop);
                weekVO.setL1("-");
                weekVO.setL2("-");
                sauList.add(weekVO);
            }
            return sauList;
        }

        for (String workshop : workshopList) {
            double a1 = 0 ;
            double l1 = 0 ;
            double l2 = 0 ;
            SelectAllWorkshopUtilizationVO weekVO = new SelectAllWorkshopUtilizationVO();
            for (SelectAllUtilizationVO selectAllUtilizationVO : list) {
                String workshopSql = selectAllUtilizationVO.getWorkshop();
                if (workshopSql.equals(workshop)) {
                    a1 += Double.parseDouble(selectAllUtilizationVO.getActualOutputArea());
                    l1 += Double.parseDouble(selectAllUtilizationVO.getTheoreticalOutputArea1());
                    l2 += Double.parseDouble(selectAllUtilizationVO.getTheoreticalOutputArea2());
                }
            }
            weekVO.setWorkshop(workshop);
            if (a1 == 0 || l1 ==0 || l2 == 0 ){
                weekVO.setL1("-");
                weekVO.setL2("-");
            }else{
                weekVO.setL1(Common.transformTwoNumber(a1/l1*100));
                weekVO.setL2(Common.transformTwoNumber(a1/l2*100));
            }
            sauList.add(weekVO);
        }
        return sauList;
    }

    /** 趋势图 1 - 3
     * 图表 - 查询涂布机台综合日利用率
     */
    public List<SelectAllMachineUtilizationVO> queryAllMachineUtilization(String workshop,String date){
        log.debug("开始执行<查询涂布机台综合日利用率>方法...");
        List<SelectAllMachineUtilizationVO> sauList = new ArrayList<>();
        // 查询机台
        List<String> machineList = readUtilizationMapper.selectMachineByWorkshop(workshop);
        // 查询
        List<SelectAllUtilizationVO> list = readUtilizationMapper.queryAllMachineUtilizationByWorkshopAndDate(workshop,date);
        if (list.size() == 0){
            for (String machine : machineList) {
                SelectAllMachineUtilizationVO vo = new SelectAllMachineUtilizationVO();
                vo.setMachine(machine);
                vo.setL1("-");
                vo.setL2("-");
                sauList.add(vo);
            }
            return sauList;
        }
        for (String machine : machineList) {
            SelectAllMachineUtilizationVO vo = new SelectAllMachineUtilizationVO();
            double a1 = 0 ;
            double l1 = 0 ;
            double l2 = 0 ;
            for (SelectAllUtilizationVO selectAllUtilizationVO : list) {
                String machineName = selectAllUtilizationVO.getMachineName();
                if (machineName.equals(machine)) {
                    a1 += Double.parseDouble(selectAllUtilizationVO.getActualOutputArea());
                    l1 += Double.parseDouble(selectAllUtilizationVO.getTheoreticalOutputArea1());
                    l2 += Double.parseDouble(selectAllUtilizationVO.getTheoreticalOutputArea2());
                }
            }
            vo.setMachine(machine);
            if (a1 == 0 || l1 == 0 || l2 == 0){
                vo.setL1("-");
                vo.setL2("-");
            }else{
                vo.setL1(Common.transformTwoNumber(a1/l1*100));
                vo.setL2(Common.transformTwoNumber(a1/l2*100));
            }
            sauList.add(vo);
        }
        return sauList;
    }

    /** 趋势图 2 - 1
     * 图表 - 查询涂布综合六周利用率
     */
    public List<SelectAllUtilizationWeekFigVO> queryAllWeekUtilization(){
        log.debug("开始执行<查询涂布综合六周利用率>方法...");
        List<SelectAllUtilizationWeekFigVO> list = new ArrayList<>();
        List<String> weekList = Common.getSixWeek();

        for (String week : weekList) {
            double a1 = 0 ;
            double l1 = 0 ;
            double l2 = 0 ;
            SelectAllUtilizationWeekFigVO weekVO = new SelectAllUtilizationWeekFigVO();
            List<SelectAllUtilizationVO> utilizationWeekVOS = readUtilizationMapper.queryAllUtilizationWeek(week);
            if (utilizationWeekVOS == null || utilizationWeekVOS.size() == 0) {
                weekVO.setWeek(week);
                weekVO.setL1("-");
                weekVO.setL2("-");
                list.add(weekVO);
                continue;
            }
            for (SelectAllUtilizationVO utilizationWeekVO : utilizationWeekVOS) {
                a1 += Double.parseDouble(utilizationWeekVO.getActualOutputArea());
                l1 += Double.parseDouble(utilizationWeekVO.getTheoreticalOutputArea1());
                l2 += Double.parseDouble(utilizationWeekVO.getTheoreticalOutputArea2());
            }
            weekVO.setWeek(week);
            weekVO.setL1(Common.transformTwoNumber(a1/l1*100));
            weekVO.setL2(Common.transformTwoNumber(a1/l2*100));
            list.add(weekVO);
        }
        log.debug("执行<查询涂布综合六周利用率>方法完毕!");
        return list;
    }

    /** 趋势图 2 - 2
     * 图表 - 查询涂布综合车间周利用率
     */
    public List<SelectAllUtilizationWeekWorkshopFigVO> queryAllWeekWorkshopUtilization(String week){
        log.debug("开始执行<查询涂布综合周车间利用率>方法...");
        // 车间集合
        List<SelectAllUtilizationWeekWorkshopFigVO> list = new ArrayList<>();
        List<String> workshopList = Common.getAllWorkshop();
        List<SelectAllUtilizationVO> utilizationWeekVOS = readUtilizationMapper.queryAllWeekWorkshopUtilization(week);
        if (utilizationWeekVOS.size() == 0){
            for (String workshop : workshopList) {
                SelectAllUtilizationWeekWorkshopFigVO s = new SelectAllUtilizationWeekWorkshopFigVO();
                s.setWorkshop(workshop);
                s.setL1("-");
                s.setL2("-");
                list.add(s);
            }
            return list;
        }
        for (String workshop : workshopList) {
            double a1 = 0 ;
            double l1 = 0 ;
            double l2 = 0 ;
            SelectAllUtilizationWeekWorkshopFigVO s = new SelectAllUtilizationWeekWorkshopFigVO();
            for (SelectAllUtilizationVO utilizationWeekVO : utilizationWeekVOS) {
                String voWorkshop = utilizationWeekVO.getWorkshop();
                if (voWorkshop.equals(workshop)) {
                    a1 += Double.parseDouble(utilizationWeekVO.getActualOutputArea());
                    l1 += Double.parseDouble(utilizationWeekVO.getTheoreticalOutputArea1());
                    l2 += Double.parseDouble(utilizationWeekVO.getTheoreticalOutputArea2());
                }
            }
            s.setWorkshop(workshop);
            if (a1 == 0 || l1 == 0 || l2 == 0) {
                s.setL1("-");
                s.setL2("-");
            }else {
                s.setL1(Common.transformTwoNumber(a1/l1*100));
                s.setL2(Common.transformTwoNumber(a1/l2*100));
            }
            list.add(s);
        }
        log.debug("执行<查询涂布综合周车间利用率>方法完毕!");
        return list;
    }

    /** 趋势图 2 - 3
     * 图表 - 查询涂布综合机台周利用率
     */
    public List<SelectAllUtilizationWeekMachineFigVO> queryAllWeekMachineUtilization(String week,String workshop){
        // 获取机台
        log.debug("开始执行<查询涂布综合机台周利用率>方法...");
        List<SelectAllUtilizationWeekMachineFigVO> sauList = new ArrayList<>();
        // 查询机台
        List<String> machineList = readUtilizationMapper.selectMachineByWorkshop(workshop);
        List<SelectAllUtilizationVO> list = readUtilizationMapper.queryAllMachineUtilizationByWorkshopAndWeek(week,workshop);
        if (list.size() == 0){
            for (String machine : machineList) {
                SelectAllUtilizationWeekMachineFigVO s = new SelectAllUtilizationWeekMachineFigVO();
                s.setMachine(machine);
                s.setL1("-");
                s.setL2("-");
                sauList.add(s);
            }
            return sauList;
        }
        for (String machine : machineList) {
            double a1 = 0 ;
            double l1 = 0 ;
            double l2 = 0 ;
            SelectAllUtilizationWeekMachineFigVO s = new SelectAllUtilizationWeekMachineFigVO();
            for (SelectAllUtilizationVO selectAllUtilizationVO : list) {
                String machineName = selectAllUtilizationVO.getMachineName();
                if (machineName.equals(machine)) {
                    a1 += Double.parseDouble(selectAllUtilizationVO.getActualOutputArea());
                    l1 += Double.parseDouble(selectAllUtilizationVO.getTheoreticalOutputArea1());
                    l2 += Double.parseDouble(selectAllUtilizationVO.getTheoreticalOutputArea2());
                }
            }
            s.setMachine(machine);
            if (a1 == 0 || l1 ==0 || l2 == 0) {
                s.setL1("-");
                s.setL2("-");
            }else{
                s.setL1(Common.transformTwoNumber(a1/l1*100));
                s.setL2(Common.transformTwoNumber(a1/l2*100));
            }
            sauList.add(s);
        }
        log.debug("执行<查询涂布综合机台周利用率>方法完毕!");
        return sauList;
    }

    /** 趋势图 3 - 1
     * 图表 - 查询涂布综合整体月利用率
     */
    public List<SelectAllUtilizationMonthFigVO> queryAllMonthUtilization(){
        log.debug("开始执行<查询综合月利用率>方法...");
        List<SelectAllUtilizationMonthFigVO> list = new ArrayList<>();
        List<String> monthList = Common.getTenTwoMonth();

        // 根据开始/结束日期查询日利用率
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        YearMonth start = YearMonth.parse(monthList.get(0), formatter);
        YearMonth end = YearMonth.parse(monthList.get(monthList.size()-1), formatter);

        String firstDay = String.valueOf(start.atDay(1));
        String lastDay = String.valueOf(end.atEndOfMonth());
        // 查询六个月的日利用率
        List<SelectAllUtilizationVO> utilizationDayVOS = readUtilizationMapper.queryAllUtilizationMonth(firstDay, lastDay);
        if (utilizationDayVOS == null || utilizationDayVOS.size() == 0){
            for (String yearMonth : monthList) {
                SelectAllUtilizationMonthFigVO s = new SelectAllUtilizationMonthFigVO();
                s.setYearMonth(yearMonth);
                s.setL1("-");
                s.setL2("-");
                list.add(s);
            }
            return list;
        }
        for (String yearMonth : monthList) {
            double o1 = 0 ;
            double l1 = 0 ;
            double l2 = 0 ;
            SelectAllUtilizationMonthFigVO s = new SelectAllUtilizationMonthFigVO();
            // 2023-12    2023-12-01
            for (SelectAllUtilizationVO dayVO : utilizationDayVOS) {
                String yM = dayVO.getDate().substring(0,7);
                if (yearMonth.equals(yM)) {
                    o1 += Double.parseDouble(dayVO.getActualOutputArea());
                    l1 += Double.parseDouble(dayVO.getTheoreticalOutputArea1());
                    l2 += Double.parseDouble(dayVO.getTheoreticalOutputArea2());
                }
            }
            s.setYearMonth(yearMonth);
            if (Common.isNumber(Common.transformTwoNumber(o1/l1*100))) {
                s.setL1(Common.transformTwoNumber(o1/l1*100));
            }else{
                s.setL1("-");
            }
            if (Common.isNumber(Common.transformTwoNumber(o1/l2*100))) {
                s.setL2(Common.transformTwoNumber(o1/l2*100));
            }else{
                s.setL2("-");
            }
            list.add(s);
        }
        log.debug("执行<查询综合月利用率>方法完毕!");
        return list;
    }

    /** 趋势图 3 - 2
     * 图表 - 查询涂布综合车间月利用率
     */
    public List<SelectAllUtilizationMonthWorkshopFigVO> queryAllMonthWorkshopUtilization(String yearMonth){
        log.debug("开始执行<查询涂布综合车间月利用率>方法...");
        // 获取车间集合
        List<SelectAllUtilizationMonthWorkshopFigVO> list = new ArrayList<>();
        List<String> workshopList = Common.getAllWorkshop();
        // 根据开始/结束日期查询日利用率
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        YearMonth date = YearMonth.parse(yearMonth, formatter);

        String firstDay = String.valueOf(date.atDay(1));
        String lastDay = String.valueOf(date.atEndOfMonth());
        // 查询六个月的日利用率
        List<SelectAllUtilizationVO> utilizationDayVOS = readUtilizationMapper.queryAllUtilizationMonthWorkshop(firstDay, lastDay);
        if (utilizationDayVOS.size() == 0){
            for (String workshop : workshopList) {
                SelectAllUtilizationMonthWorkshopFigVO s = new SelectAllUtilizationMonthWorkshopFigVO();
                s.setWorkshop(workshop);
                s.setL1("-");
                s.setL2("-");
                list.add(s);
            }
            return list;
        }
        for (String workshop : workshopList) {
            double a1 = 0 ;
            double l1 = 0 ;
            double l2 = 0 ;
            SelectAllUtilizationMonthWorkshopFigVO s = new SelectAllUtilizationMonthWorkshopFigVO();
            for (SelectAllUtilizationVO utilizationDayVO : utilizationDayVOS) {
                String voWorkshop = utilizationDayVO.getWorkshop();
                if (voWorkshop.equals(workshop)){
                    a1 += Double.parseDouble(utilizationDayVO.getActualOutputArea());
                    l1 += Double.parseDouble(utilizationDayVO.getTheoreticalOutputArea1());
                    l2 += Double.parseDouble(utilizationDayVO.getTheoreticalOutputArea2());
                }
            }
            s.setWorkshop(workshop);
            if (a1 == 0 || l1 == 0 || l2 == 0){
                s.setL1("-");
                s.setL2("-");
            }else{
                s.setL1(Common.transformTwoNumber(a1/l1*100));
                s.setL2(Common.transformTwoNumber(a1/l2*100));
            }
            list.add(s);
        }
        log.debug("执行<查询涂布综合车间月利用率>方法完毕!");
        return list;
    }

    /** 趋势图 3 - 3
     * 图表 - 查询涂布综合机台月利用率
     */
    public List<SelectAllUtilizationMonthMachineFigVO> queryAllMonthMachineUtilization(String yearMonth,String workshop){
        log.debug("开始执行<查询涂布综合机台月利用率>方法...");
        // 获取机台集合
        List<SelectAllUtilizationMonthMachineFigVO> list = new ArrayList<>();
        List<String> machineList = readUtilizationMapper.selectMachineByWorkshop(workshop);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        YearMonth date = YearMonth.parse(yearMonth, formatter);

        String firstDay = String.valueOf(date.atDay(1));
        String lastDay = String.valueOf(date.atEndOfMonth());
        List<SelectAllUtilizationVO> selectAllUtilizationVOS
                = readUtilizationMapper.queryAllUtilizationMonthMachineByDateAndWorkshop(firstDay, lastDay, workshop);
        if (selectAllUtilizationVOS.size() == 0){
            for (String machine : machineList) {
                SelectAllUtilizationMonthMachineFigVO s =  new SelectAllUtilizationMonthMachineFigVO();
                s.setMachine(machine);
                s.setL1("-");
                s.setL2("-");
                list.add(s);
            }
            return list;
        }
        for (String machine : machineList) {
            double a1 = 0 ;
            double l1 = 0 ;
            double l2 = 0 ;
            SelectAllUtilizationMonthMachineFigVO s =  new SelectAllUtilizationMonthMachineFigVO();
            for (SelectAllUtilizationVO selectAllUtilizationVO : selectAllUtilizationVOS) {
                String machineName = selectAllUtilizationVO.getMachineName();
                if (machine.equals(machineName)){
                    a1 += Double.parseDouble(selectAllUtilizationVO.getActualOutputArea());
                    l1 += Double.parseDouble(selectAllUtilizationVO.getTheoreticalOutputArea1());
                    l2 += Double.parseDouble(selectAllUtilizationVO.getTheoreticalOutputArea2());
                }
            }
            s.setMachine(machine);
            if (a1 == 0 || l1 == 0 || l2 == 0){
                s.setL1("-");
                s.setL2("-");
            }else{
                s.setL1(Common.transformTwoNumber(a1/l1*100));
                s.setL2(Common.transformTwoNumber(a1/l2*100));
            }
            list.add(s);
        }
        log.debug("执行<查询涂布综合机台月利用率>方法完毕!");
        return list;
    }

    /** 趋势图 4 - 1
     * 图表 - 查询涂布综合月类型利用率
     */
    public List<SelectAllUtilizationMonthModelFigVO> queryAllMonthModelUtilization(String slurryModel){
        log.debug("开始执行<查询涂布综合月类型利用率>方法...");
        List<SelectAllUtilizationMonthModelFigVO> list = new ArrayList<>();
        List<String> monthList = Common.getTenTwoMonth();
        for (String yearMonth : monthList) {
            double a1 = 0 ;
            double l1 = 0 ;
            double l2 = 0;
            SelectAllUtilizationMonthModelFigVO s = new SelectAllUtilizationMonthModelFigVO();
            // 查询该类型在该月的利用率
            List<UtilizationShiftVO> utilizationShiftVOS = readUtilizationMapper.queryAllMonthModelUtilization(slurryModel, yearMonth);
            if (utilizationShiftVOS.size() != 0) {
                for (UtilizationShiftVO utilizationShiftVO : utilizationShiftVOS) {
                    if (Common.isNumber(utilizationShiftVO.getActualOutputArea())){
                        a1 += Double.parseDouble(utilizationShiftVO.getActualOutputArea());
                    }
                    if (Common.isNumber(utilizationShiftVO.getTheoreticalOutputArea1())){
                        l1 += Double.parseDouble(utilizationShiftVO.getTheoreticalOutputArea1());
                    }
                    if (Common.isNumber(utilizationShiftVO.getTheoreticalOutputArea2())){
                        l2 += Double.parseDouble(utilizationShiftVO.getTheoreticalOutputArea2());
                    }
                }
            }
            s.setSlurryModel(slurryModel);
            s.setYearMonth(yearMonth);
            if (a1 == 0 || l1 == 0 || l2 == 0){
                s.setL1("-");
                s.setL2("-");
            }else{
                s.setL1(Common.transformTwoNumber(a1/l1*100));
                s.setL2(Common.transformTwoNumber(a1/l2*100));
            }
            list.add(s);
        }
        log.debug("执行<查询涂布综合月类型利用率>方法完毕!");
        return list;
    }

    /** 趋势图 4 - 2
     * 图表 - 查询涂布综合周类型利用率
     */
    public List<SelectAllUtilizationWeekModelFigVO> queryAllWeekModelUtilization(String slurryModel){
        log.debug("开始执行<查询涂布综合周类型利用率>方法...");
        List<SelectAllUtilizationWeekModelFigVO> list = new ArrayList<>();
        List<String> weekList = Common.getSixWeek();

        for (String week : weekList) {
            double a1 = 0 ;
            double l1 = 0 ;
            double l2 = 0 ;
            SelectAllUtilizationWeekModelFigVO s = new SelectAllUtilizationWeekModelFigVO();
            List<UtilizationShiftVO> utilizationShiftVOS = readUtilizationMapper.queryAllWeekModelUtilization(slurryModel, week);
            if (utilizationShiftVOS.size() != 0) {
                for (UtilizationShiftVO utilizationShiftVO : utilizationShiftVOS) {
                    a1 += Double.parseDouble(utilizationShiftVO.getActualOutputArea());
                    l1 += Double.parseDouble(utilizationShiftVO.getTheoreticalOutputArea1());
                    l2 += Double.parseDouble(utilizationShiftVO.getTheoreticalOutputArea2());
                }
            }
            s.setWeek(week);
            if (a1 == 0 || l1 == 0 || l2 == 0){
                s.setL1("-");
                s.setL2("-");
            }else{
                s.setL1(Common.transformTwoNumber(a1/l1*100));
                s.setL2(Common.transformTwoNumber(a1/l2*100));
            }
            list.add(s);
        }
        log.debug("执行<查询涂布综合周类型利用率>方法完毕!");
        return list;
    }

    /** 单系列查询 5 - 1
     * 图表 - 查询日次类型
     */
    public List<SelectSeriesUtilizationFigVO> querySeriesUtilizationDayFigVO(SelectSeriesUtilizationDayFigDTO dto){
        // 查询时间范围
        String start = String.valueOf(LocalDate.parse(dto.getStart().split("T")[0]).plusDays(1));
        String end = String.valueOf(LocalDate.parse(dto.getEnd().split("T")[0]).plusDays(1));
        String state = "异常/停机/实验";

        List<SelectSeriesUtilizationFigVO> list = new ArrayList<>();
        String machine = dto.getMachine();
        String workshop = dto.getWorkshop();
        // 将日期字符串转换为 LocalDate 对象
        LocalDate startDate = LocalDate.parse(start);
        LocalDate endDate = LocalDate.parse(end);
        // 获取两个日期之间的全部日期集合
        List<String> allDates = getAllDatesBetweenTwoDates(startDate, endDate);
        if (machine.equals("")){
            // 查询车间日
            List<SelectAllUtilizationVO> selectAllUtilizationVOS = readUtilizationMapper.querySeriesWorkshopUtilizationByTimeRang(start, end, workshop,state);
            for (String date : allDates) {
                double a1 = 0 ;
                double l1 = 0 ;
                double l2 = 0 ;
                SelectSeriesUtilizationFigVO s = new SelectSeriesUtilizationFigVO();
                if (selectAllUtilizationVOS.size() != 0){
                    for (SelectAllUtilizationVO vo : selectAllUtilizationVOS) {
                        String voDate = vo.getDate();
                        if (voDate.equals(date)){
                            a1 += Double.parseDouble(vo.getActualOutputArea());
                            l1 += Double.parseDouble(vo.getTheoreticalOutputArea1());
                            l2 += Double.parseDouble(vo.getTheoreticalOutputArea2());
                        }
                    }
                }
                s.setX(date);
                if (a1 == 0 || l1 == 0 || l2 == 0){
                    s.setL1("-");
                    s.setL2("-");
                }else{
                    s.setL1(Common.transformTwoNumber(a1/l1*100));
                    s.setL2(Common.transformTwoNumber(a1/l2*100));
                }
                list.add(s);
            }
        }else{
            // 查询机台日
            List<SelectAllUtilizationVO> selectAllUtilizationVOS1 = readUtilizationMapper.querySeriesMachineUtilizationByTimeRang(start, end, machine);
            for (String date : allDates) {
                double a1 = 0 ;
                double l1 = 0 ;
                double l2 = 0 ;
                SelectSeriesUtilizationFigVO s = new SelectSeriesUtilizationFigVO();
                if (selectAllUtilizationVOS1.size() != 0){
                    for (SelectAllUtilizationVO vo : selectAllUtilizationVOS1) {
                        String voDate = vo.getDate();
                        if (voDate.equals(date)){
                            a1 += Double.parseDouble(vo.getActualOutputArea());
                            l1 += Double.parseDouble(vo.getTheoreticalOutputArea1());
                            l2 += Double.parseDouble(vo.getTheoreticalOutputArea2());
                        }
                    }
                }
                s.setX(date);
                if (a1 == 0 || l1 == 0 || l2 == 0){
                    s.setL1("-");
                    s.setL2("-");
                }else{
                    s.setL1(Common.transformTwoNumber(a1/l1*100));
                    s.setL2(Common.transformTwoNumber(a1/l2*100));
                }
                list.add(s);
            }
        }
        return list;
    }


    public List<SelectSeriesUtilizationFigVO> loadQuerySeriesUtilizationDayFigVO(){
        LocalDate start = Common.getBeforeNowDate();
        LocalDate end = Common.getBeforeTenDate();
        String workshop = "涂布A2车间";
        List<SelectSeriesUtilizationFigVO> list = new ArrayList<>();
        String state = "异常/停机/实验";


        List<String> allDates = getAllDatesBetweenTwoDates(end, start);
        // 查询车间日
        List<SelectAllUtilizationVO> selectAllUtilizationVOS = readUtilizationMapper.querySeriesWorkshopUtilizationByTimeRang(String.valueOf(end), String.valueOf(start), workshop,state);
        if (selectAllUtilizationVOS.size() != 0){
            for (String date : allDates) {
                SelectSeriesUtilizationFigVO s = new SelectSeriesUtilizationFigVO();
                s.setX(date);
                s.setL1("-");
                s.setL2("-");
                list.add(s);
            }
            return list;
        }

        for (String date : allDates) {
            double a1 = 0 ;
            double l1 = 0 ;
            double l2 = 0 ;
            SelectSeriesUtilizationFigVO s = new SelectSeriesUtilizationFigVO();
            for (SelectAllUtilizationVO vo : selectAllUtilizationVOS) {
                String voDate = vo.getDate();
                if (voDate.equals(date)){
                    a1 += Double.parseDouble(vo.getActualOutputArea());
                    l1 += Double.parseDouble(vo.getTheoreticalOutputArea1());
                    l2 += Double.parseDouble(vo.getTheoreticalOutputArea2());
                }
            }

            s.setX(date);
            if (a1 == 0 || l1 == 0 || l2 == 0){
                s.setL1("-");
                s.setL2("-");
            }else{
                s.setL1(Common.transformTwoNumber(a1/l1*100));
                s.setL2(Common.transformTwoNumber(a1/l2*100));
            }
            list.add(s);
        }
        return list;
    }

    /** 单系列查询 5 - 2
     * 图表 - 查询周次类型
     */
    public List<SelectSeriesUtilizationFigVO> querySeriesUtilizationWeekFigVO(String workshop,String machine){
        log.debug("开始执行<查询周次类型>方法...");
        List<SelectSeriesUtilizationFigVO> list = new ArrayList<>();
        List<String> weekList = Common.getSixWeek();
        String state = "异常/停机/实验";
        if (machine.equals("")){
            for (String week : weekList) {
                double a1 = 0 ;
                double l1 = 0 ;
                double l2 = 0 ;
                SelectSeriesUtilizationFigVO s = new SelectSeriesUtilizationFigVO();
                s.setX(String.valueOf(week));
                List<SelectAllUtilizationVO> selectAllUtilizationVOS = readUtilizationMapper.queryAllUtilizationWeekByWorkshop(week, workshop,state);
                if (selectAllUtilizationVOS.size() == 0){
                    s.setL1("-");
                    s.setL2("-");
                    list.add(s);
                    continue;
                }
                for (SelectAllUtilizationVO vo : selectAllUtilizationVOS) {
                    a1 += Double.parseDouble(vo.getActualOutputArea());
                    l1 += Double.parseDouble(vo.getTheoreticalOutputArea1());
                    l2 += Double.parseDouble(vo.getTheoreticalOutputArea2());
                }
                s.setL1(Common.transformTwoNumber(a1/l1*100));
                s.setL2(Common.transformTwoNumber(a1/l2*100));
                list.add(s);
            }
        }else{
            for (String week : weekList) {
                double a1  = 0 ;
                double l1 = 0 ;
                double l2 = 0 ;
                SelectSeriesUtilizationFigVO s = new SelectSeriesUtilizationFigVO();
                s.setX(String.valueOf(week));
                List<SelectAllUtilizationVO> selectAllUtilizationVOS = readUtilizationMapper.queryAllUtilizationWeekByMachine(week, machine,state);
                if (selectAllUtilizationVOS == null || selectAllUtilizationVOS.size() == 0){
                    s.setL1("-");
                    s.setL2("-");
                    list.add(s);
                    continue;
                }
                for (SelectAllUtilizationVO vo : selectAllUtilizationVOS) {
                    a1 += Double.parseDouble(vo.getActualOutputArea());
                    l1 += Double.parseDouble(vo.getTheoreticalOutputArea1());
                    l2 += Double.parseDouble(vo.getTheoreticalOutputArea2());
                }

                s.setL1(Common.transformTwoNumber(a1/l1*100));
                s.setL2(Common.transformTwoNumber(a1/l2*100));
                list.add(s);
            }
        }
        log.debug("执行<查询周次类型>方法完毕!");
        return list;
    }

    /** 单系列查询 5 - 3
     * 图表 - 查询月次类型
     */
    public List<SelectSeriesUtilizationFigVO> querySeriesUtilizationMonthFigVO(String workshop,String machine) {
        log.debug("开始执行<查询月次类型>方法...");
        List<SelectSeriesUtilizationFigVO> list = new ArrayList<>();
        List<String> monthList = Common.getTenTwoMonth();
        // 根据开始/结束日期查询日利用率
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
        YearMonth start = YearMonth.parse(monthList.get(0), formatter);
        YearMonth end = YearMonth.parse(monthList.get(monthList.size() - 1), formatter);

        String firstDay = String.valueOf(start.atDay(1));
        String lastDay = String.valueOf(end.atEndOfMonth());
        String state = "异常/停机/实验";
        if (machine.equals("")) {
            List<SelectAllUtilizationVO> selectAllUtilizationVOS = readUtilizationMapper.queryAllUtilizationMonthByWorkshop(firstDay, lastDay, workshop,state);
            for (String yearMonth : monthList) {
                double a1 = 0;
                double l1 = 0;
                double l2 = 0;
                SelectSeriesUtilizationFigVO s = new SelectSeriesUtilizationFigVO();
                if (selectAllUtilizationVOS.size() != 0){
                    for (SelectAllUtilizationVO vo : selectAllUtilizationVOS) {
                        String ss = vo.getYearMonth();
                        if (ss.equals(yearMonth) && !vo.getState().equals("异常/停机/实验")) {
                            a1 += Double.parseDouble(vo.getActualOutputArea());
                            l1 += Double.parseDouble(vo.getTheoreticalOutputArea1());
                            l2 += Double.parseDouble(vo.getTheoreticalOutputArea2());
                        }
                    }
                }
                s.setX(yearMonth);
                if (a1 == 0 || l1 == 0 || l2 == 0) {
                    s.setL1("-");
                    s.setL2("-");
                } else {
                    s.setL1(Common.transformTwoNumber(a1 / l1 * 100));
                    s.setL2(Common.transformTwoNumber(a1 / l2 * 100));
                }
                list.add(s);
            }
        } else {
            List<SelectAllUtilizationVO> selectAllUtilizationVOS = readUtilizationMapper.queryAllUtilizationMonthByMachine(firstDay, lastDay, machine,state);
            for (String yearMonth : monthList) {
                double a1 = 0;
                double l1 = 0;
                double l2 = 0;
                SelectSeriesUtilizationFigVO s = new SelectSeriesUtilizationFigVO();
                if (selectAllUtilizationVOS.size() != 0){
                    for (SelectAllUtilizationVO vo : selectAllUtilizationVOS) {
                        String ss = vo.getYearMonth();
                        if (ss.equals(yearMonth)) {
                            a1 += Double.parseDouble(vo.getActualOutputArea());
                            l1 += Double.parseDouble(vo.getTheoreticalOutputArea1());
                            l2 += Double.parseDouble(vo.getTheoreticalOutputArea2());
                        }
                    }
                }
                s.setX(yearMonth);
                if (a1 == 0 || l1 == 0 || l2 == 0) {
                    s.setL1("-");
                    s.setL2("-");
                } else {
                    s.setL1(Common.transformTwoNumber(a1 / l1 * 100));
                    s.setL2(Common.transformTwoNumber(a1 / l2 * 100));
                }
                list.add(s);
            }
        }
        return list;
    }


    /**
     * 源查询 - 初始化
     */
    public List<SelectCoatingBasicVO> queryLoadBeginBasicVO(){
        String date = String.valueOf(Common.getBeforeNowDate());
        return readUtilizationMapper.querySelectBeginBasicVO(date);
    }
    /**
     * 源查询 - 查询
     */
    public <T> List<T> queryBasicByDateRangAndModel(String first,String one,String model){
        String start = String.valueOf(LocalDate.parse(first.split("T")[0]).plusDays(1));
        String end = String.valueOf(LocalDate.parse(one.split("T")[0]).plusDays(1));
        if (model.equals("制浆")){
            return (List<T>) readUtilizationMapper.queryBasicByPulpingRangAndModel(start, end);
        }

        if (model.equals("涂布")){
            return (List<T>) readUtilizationMapper.queryBasicByCoatingRangAndModel(start, end);
        }
        List<String> list = new ArrayList<>();
        return (List<T>) list;
    }





    /** 内部接口
     * 基础 - 导入制浆领用数据
     */
    public List<Integer> quartzInsertPulpingDate(String sheetUrl) {
        List<PulpingDateDTO> list = new ArrayList<>();
        ReadPulpingDateListener readPulping = new ReadPulpingDateListener(list);
        EasyExcel.read(sheetUrl, PulpingDateDTO.class,readPulping)
                .sheet("浆料领用记录表").doRead();

        List<PulpingDateDTO> pulpingDateDTOList1 = readPulping.getPulpingDateDTOList();
        if (pulpingDateDTOList1.size() == 0 || pulpingDateDTOList1.size() > 99999){
            throw new ServiceException(ResponseCode.BAD_REQUEST,"导入失败,请重新检查模板或超过最大条数99999!");
        }
        // 指定转换格式
//        Pattern pattern = Pattern.compile(regex);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

        for (PulpingDateDTO dto : pulpingDateDTOList1) {
//            if (!pattern.matcher(dto.getDate()).matches()) {
//                throw new ServiceException(ResponseCode.BAD_REQUEST, "日期格式错误,请提供纯数字格式!");
//            }
            // 转换Excel序列号为Java Date对象
            Date dateValue = new Date((long)(Double.parseDouble(dto.getDate()) - 25569) * (24 * 60 * 60 * 1000)); // Excel 1900日期系统需要减去25569

            // 格式化日期
            String formattedDate = sdf.format(dateValue);
            dto.setDate(formattedDate);
        }

        // 分批导入
        List<List<PulpingDateDTO>> partitionedList = Lists.partition(pulpingDateDTOList1, 3000);
        for (List<PulpingDateDTO> partition : partitionedList) {
            readUtilizationMapper.insertPulpingDate(partition);
        }
        return Lists.newArrayList(pulpingDateDTOList1.size(),partitionedList.size());
    }

    /**内部接口
     * 基础 - 导入涂布产出数据
     */
    public List<Integer> quartzInsertCoatingDate(String sheetUrl) {
        List<CoatingDateDTO> list = new ArrayList<>();
        ReadCoatingDateListener readCoating = new ReadCoatingDateListener(list);
        EasyExcel.read(sheetUrl, CoatingDateDTO.class,readCoating)
                .sheet("浆料使用记录表").doRead();

        List<CoatingDateDTO> coatingDateDTOList1 = readCoating.getCoatingDateDTOList();
        if (coatingDateDTOList1.size() == 0 || coatingDateDTOList1.size() > 99999){
            throw new ServiceException(ResponseCode.BAD_REQUEST,"导入失败,请重新检查模板或超过最大条数99999!");
        }
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for (CoatingDateDTO dto : coatingDateDTOList1) {
            // 转换Excel序列号为Java Date对象
            Date dateValue = new Date((long)(Double.parseDouble(dto.getDate()) - 25569) * (24 * 60 * 60 * 1000)); // Excel 1900日期系统需要减去25569
            // 格式化日期
            String formattedDate = sdf.format(dateValue);
            dto.setDate(formattedDate);
        }

        // 分批导入
        List<List<CoatingDateDTO>> partitionedList = Lists.partition(coatingDateDTOList1, 3000);
        for (List<CoatingDateDTO> partition : partitionedList) {
            readUtilizationMapper.insertCoatingDate(partition);
        }
        return Lists.newArrayList(coatingDateDTOList1.size(),partitionedList.size());
    }


    /**内部接口
     * 基础 - 导入课程
     */
    public Integer quartzInsertClassDate(String sheetUrl) {
        List<ClassDataDTO> list = new ArrayList<>();
        ReadClassDateListener readClass = new ReadClassDateListener(list);
        EasyExcel.read(sheetUrl, ClassDataDTO.class, readClass)
                .sheet("课程列表").doRead();

        List<ClassDataDTO> coatingDateDTOList1 = readClass.getClassDateDTOList();
        if (coatingDateDTOList1.size() == 0 || coatingDateDTOList1.size() > 99){
            throw new ServiceException(ResponseCode.BAD_REQUEST,"导入失败,请重新检查模板或超过最大条数99!");
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        for (ClassDataDTO dto : coatingDateDTOList1) {
            // 转换Excel序列号为Java Date对象
            Date dateValue = new Date((long)(Double.parseDouble(dto.getMakeDate()) - 25569) * (24 * 60 * 60 * 1000)); //减去25569
            // 格式化日期
            String formattedDate = sdf.format(dateValue);
            dto.setMakeDate(formattedDate);
        }
        readUtilizationMapper.insertClassDate(coatingDateDTOList1);
        return coatingDateDTOList1.size();
    }

    public List<String> selectCoatingWorkshop() {
        return readUtilizationMapper.selectCoatingWorkshop();
    }

    public void addSolids(String slurryName, String model, String solids) {
        readUtilizationMapper.addSolids(slurryName,model,solids);
    }
}//class
